package defectsim.agents;

import javax.vecmath.Vector2d;

import defectsim.material.SlipSystem;
import defectsim.resources.AllForces;

public abstract class Dislocation extends DefectAgent{
	protected boolean mobility; // mobility = true if mobile, false if immobile
	private boolean dipole; // dipole = true if dipole, false if monopole
	protected boolean pinned; 
	private Dislocation dipoleMate = null;
	protected Vector2d velocity;
	protected Vector2d acceleration;
	protected Vector2d distance;
	private double deltaTime;
	private double direction;
	private double unitBurgersVector;
	private Dislocation[] dipoleMates = new Dislocation[4];
	private AllForces allForces = new AllForces();
	private SlipSystem slipSystem = new SlipSystem();
	private Vector2d effectiveStress = new Vector2d();
	private Vector2d netStress = new Vector2d();

	public SlipSystem getSlipSystem() {
		return slipSystem;
	}

	public void setSlipSystem(SlipSystem slipSystem) {
		this.slipSystem = slipSystem;
		this.direction = slipSystem.getGlideAngle();
	}

	public AllForces getForces() {
		return allForces;
	}

	public void setForces(AllForces allForces) {
		this.allForces = allForces;
	}

	public boolean isMobile() {
		return mobility;
	}

	public boolean isDipole() {
		return dipole;
	}

	public boolean isPinned() {
		return pinned;
	}

	public void setPinned() {
		this.pinned = true;
		this.mobility = false;
		this.velocity = new Vector2d();
		this.distance = new Vector2d();
		this.acceleration = new Vector2d();
	}

	public void setDipole(boolean dipole) {
		if (dipole)
			this.dipole = true;
		else {
			this.dipole = false;
			this.setDipoleMate(null);
		}

	}
	
	public Vector2d getVelocity() {
		return velocity;
	}

	public void setVelocity(Vector2d velocity) {
		this.velocity = velocity;
	}

	public Vector2d getDistance() {
		return distance;
	}

	public void setDistance(Vector2d distance) {
		this.distance = distance;
	}

	public Vector2d getAcceleration() {
		return acceleration;
	}

	public void setAcceleration(Vector2d acceleration) {
		this.acceleration = acceleration;
	}

	public double getDirection() {
		return direction;
	}
	
	public Vector2d getEffectiveStress(){
		return effectiveStress;
	}

	public void setEffectiveStress(Vector2d eStress){
		effectiveStress = eStress;
	}

	public Vector2d getNetStress(){
		return netStress;
	}

	public void setNetStress(Vector2d eStress){
		netStress = eStress;
	}
	
	public double getUnitBurgersVector() {
		return unitBurgersVector;
	}

	public void setUnitBurgersVector(double unitBurgersVector) {
		this.unitBurgersVector = unitBurgersVector;
	}

	public void setDipoleMate(Dislocation dipoleMate) {
		this.dipoleMate = dipoleMate;
	}
	
	public Dislocation getDipoleMate(){
		return dipoleMate;
	}
	
	public void setDipoleMates(Dislocation dipoleMate, int quadrant){
		if (this.dipoleMates[quadrant - 1] == null)
			this.dipoleMates[quadrant - 1] = dipoleMate;
		else
			System.out.println("Dipole mate error. The mate has already been assigned!");
	}
	
	public Dislocation getDipoleMate(int quadrant){
		return this.dipoleMates[quadrant - 1];
	}

	public double getDeltaTime() {
		return deltaTime;
	}

	public void setDeltaTime(double deltaTime) {
		this.deltaTime = deltaTime;
	}

}
